package org.sunrise.game.rpc.service;

import lombok.Getter;
import org.sunrise.game.common.db.DbService;
import org.sunrise.game.common.log.LogCore;
import org.sunrise.game.rpc.function.Call;
import org.sunrise.game.rpc.function.CallUtils;
import org.sunrise.game.rpc.function.ErrorType;

@Getter
public class BaseService {

    private final String nodeId;

    public BaseService(String nodeId) {
        this.nodeId = nodeId;
        ServiceManager.registerService(this);
    }

    public void init() {
        LogCore.RpcUtils.debug("Service init start, name = { {} }", this.getClass().getName());
    }

    public DbService getDbService() {
        return ServiceManager.dbService;
    }

    public void returns(Object ... params) {
        CallUtils.returns(nodeId, ErrorType.SUCCESS, params);
    }

    public void returns(Call from, Object ... params) {
        CallUtils.returns(from, nodeId, ErrorType.SUCCESS, params);
    }
}
